测试链接：https://leetcode.cn/problems/substring-with-concatenation-of-all-words/description/
class Solution {
public:
    vector<int> findSubstring(string s, vector<string>& words) {
        if (s.empty() || words.empty())
            return {};
        int n = s.size();
        int wordSize = words.size();
        int wordsPreLen = words[0].size();
        int totalSize = wordSize * wordsPreLen;
        if (totalSize > n)
            return {};

        unordered_map<string, int> hash1;
        for (auto& e : words) {
            hash1[e]++;
        }

        int l = 0;
        int r = 0;
        string in;
        string out;
        vector<int> ans;
        for (int i = 0; i < wordsPreLen; i++) {
            l = i;
            r = i;
            int count = 0;
            unordered_map<string, int> hash2;
            while (r + wordsPreLen <= n) {//注意这里是小于等于
                in = s.substr(r, wordsPreLen);
                if (++hash2[in] <= hash1[in])
                    count++;

                // cout << r <<endl;
                if (r - l + 1 > totalSize) {
                    out = s.substr(l, wordsPreLen);
                    if (hash2[out]-- <= hash1[out])
                        count--;
                    l += wordsPreLen;
                }

                if (count == wordSize) {
                    ans.emplace_back(l);
                }
                r += wordsPreLen;
            }
        }
        return ans;
    }
};